import ora from "ora";
import longConfig from "../long.config.js";
import {downloadFile} from "./utils/fetchUtils.js";
import {getDirnameByMeterPath, pathJoin} from "./utils/pathUtils.js";
import SpinnerWrapper from "./utils/spinnerUtils.js";

const {electronCache} = longConfig;
if(!electronCache){
    throw new Error('electronCache is not defined')
}
const __dirname = getDirnameByMeterPath(import.meta.url)

const {name='electron', version="21.4.4", platform = "win32", arch = 'x64'} = electronCache
const electronFile = `${name}-v${version}-${platform}-${arch}.zip`

// const url = 'https://cdn.npmmirror.com/binaries/electron/21.4.4/electron-v21.4.4-win32-x64.zip';

const electronUrl = `https://cdn.npmmirror.com/binaries/electron/${version}/${electronFile}`
// 下载zip
const filePath = pathJoin(__dirname, '..', `modules/${electronFile}`);

let customSpinner = new SpinnerWrapper({ text: '从服务器获取数据...', color: 'yellow' });
customSpinner.runTask(downloadFile,electronUrl, filePath)
customSpinner =null
